using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ProjectCodeS.Models;

namespace ProjectCodeS.Controllers
{   
    public class ChargeCategoriesController : Controller
    {
		private readonly IChargeCategoryRepository chargecategoryRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public ChargeCategoriesController() : this(new ChargeCategoryRepository())
        {
        }

        public ChargeCategoriesController(IChargeCategoryRepository chargecategoryRepository)
        {
			this.chargecategoryRepository = chargecategoryRepository;
        }

        //
        // GET: /ChargeCategories/

        public ViewResult Index()
        {
            return View(chargecategoryRepository.AllIncluding(chargecategory => chargecategory.Stores, chargecategory => chargecategory.ServiceTypes));
        }

        //
        // GET: /ChargeCategories/Details/5

        public ViewResult Details(int id)
        {
            return View(chargecategoryRepository.Find(id));
        }

        //
        // GET: /ChargeCategories/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /ChargeCategories/Create

        [HttpPost]
        public ActionResult Create(ChargeCategory chargecategory)
        {
            if (ModelState.IsValid) {
                chargecategoryRepository.InsertOrUpdate(chargecategory);
                chargecategoryRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /ChargeCategories/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(chargecategoryRepository.Find(id));
        }

        //
        // POST: /ChargeCategories/Edit/5

        [HttpPost]
        public ActionResult Edit(ChargeCategory chargecategory)
        {
            if (ModelState.IsValid) {
                chargecategoryRepository.InsertOrUpdate(chargecategory);
                chargecategoryRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /ChargeCategories/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(chargecategoryRepository.Find(id));
        }

        //
        // POST: /ChargeCategories/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            chargecategoryRepository.Delete(id);
            chargecategoryRepository.Save();

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                chargecategoryRepository.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

